<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>会议管理系统</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="layui/css/layui.css" media="all">
		<style>
			.layui-layout-admin .layui-side{
				top: 0px;
			}
			/*.layui-body {
				overflow-y: scroll;
				overflow-x: hidden;
			}*/
			.layui-nav .layui-nav-item a{
				color:#000000;
			}
			.layui-nav-itemed >a{
				color:#000000!important;
			}
			.layui-nav{
				background-color:#eee;
			}
			.categoryClass{
				margin: 0 auto;
			}
			.category-row{
				
				display:table-row;
			}
			.category-cell{
				padding: 15px;
				display:table-cell;
			}
			.layui-table-cell {
				line-height: 40px;
			height: 40px;
			}
			.add-delt{
				padding: 10px;
			}
		</style>
	</head>

	<body class="layui-layout-body">
		<div class="layui-layout layui-layout-admin">
			<div class="layui-side layui-bg-gray">
				<ul class="layui-nav" style="top: 30px;">
					<li class="layui-nav-item layui-this">
						<button class="layui-btn layui-btn-lg layui-btn-normal"><!--<i class="layui-icon" style="font-size: 30px;">&#xe609;</i>-->欢迎使用本系统</button>
						<!--<dl class="layui-nav-child">
							<dd>
								<a href="#" id="openNewTaskDialog" >
									<i class="layui-icon" style="font-size:20px;margin-right:10px;color: #01AAED;">&#xe63c;</i>任务</a>
							</dd>
							<dd>
								<a href="#" id="openNewProjectDialog">
									<i class="layui-icon" style="font-size:20px;margin-right:10px;color: #01AAED;">&#xe622;</i>项目</a>
							</dd>
						</dl>-->
					</li>
				</ul>
				<!-- 左侧导航区域（可配合layui已有的垂直导航） -->
				<ul class="layui-nav layui-nav-tree" style="top: 40px;" lay-filter="test">
					<li class="layui-nav-item">
						<a href="index.html">
							<i class="layui-icon" style="font-size: 30px;margin-right:10px;color: #01AAED;">&#xe68e;</i>首页</a>
					</li>
					<li class="layui-nav-item">
						<a href="#" onclick="toCategorysPage()">
							<i class="layui-icon" style="font-size: 30px;margin-right:10px;color: #01AAED;">&#xe63c;</i>分类管理</a>
					</li>
					<!--<li class="layui-nav-item layui-nav-itemed">
						<a class="" href="javascript:;">所有商品</a>
						<dl class="layui-nav-child">
							<dd>
								<a href="javascript:;">列表一</a>
							</dd>
							<dd>
								<a href="javascript:;">列表二</a>
							</dd>
							<dd>
								<a href="javascript:;">列表三</a>
							</dd>
							<dd>
								<a href="">超链接</a>
							</dd>
						</dl>
					</li>-->
					<li class="layui-nav-item">
						<a href="javascript:;"><img src="img/timg.jpg" class="layui-nav-img"><b id="nickName">解决方案</b></a>
						<dl class="layui-nav-child">
							<dd>
								<a href="javascript:;"><i class="layui-icon" style="font-size:20px;margin-right:5px;color: #01AAED;">&#xe620;</i>个人设置</a>
							</dd>
							<dd>
								<a href="javascript:;" onclick="logout()"><i class="layui-icon" style="font-size:20px;margin-right:5px;color: #01AAED;">&#xe65c;</i>退出登陆</a>
							</dd>
						</dl>
					</li>

				</ul>
			</div>
		</div>

		<div class="layui-body">
			 <!--搜索-->
    <div class="demoTable">
        <!--<div class="search-box">
        	用户名:
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="keyWord" name="keyWord" placeholder="用户名关键字">
            </div>
            &nbsp;&nbsp; &nbsp;&nbsp;
		            开始时间：
		      <div class="layui-input-inline"> 
		        <input type="text" class="layui-input" id="dateStart" name="dateStart" placeholder="yyyy-MM-dd">
		      </div>
            <button id="selectButton" class="layui-btn site-demo-active" data-type="reload">搜索</button>
        </div>-->
        <div class="add-delt">
            <button id="passBtn" class="layui-btn layui-btn-sm">
                <i class="layui-icon">&#xe654;</i> 审核
            </button>
             <button id="addCategory" class="layui-btn layui-btn-sm">
                <i class="layui-icon">&#xe654;</i> 新增分类
            </button>
            <button id="delCategory" class="layui-btn layui-btn-sm  layui-btn-danger">
                <i class="layui-icon">&#xe640;</i> 删除分类
            </button>
        </div>
    </div>
    <table class="layui-hide" id="LAY_table_user" lay-filter="categories"></table>
    <!--操作-->
    <script type="text/html" id="barTool">
    	<!--<a class="layui-btn layui-btn-xs" permission="sys:order:edit" lay-event="pass">审核</a>-->
        <a class="layui-btn layui-btn-xs" permission="sys:order:edit" lay-event="setCategory">设置分类</a>
    </script>
    
     <script type="text/html" id="barTool1">
     	<a class="layui-btn layui-btn-xs" permission="sys:order:edit" lay-event="setCategory">设置分类</a>
    </script>
    <!-- 分页工具 -->
    <div class="admin-table-page" >
        <div id="paged" class="page"></div>
    </div> 
		</div>
		<script src="layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="js/ajax.js" ></script>
		<script>
			var layer;
			var $;
			//JavaScript代码区域
			 layui.use(['layer'], function(){//这里相当于js的页面初始化代码
			  layer = layui.layer; 
			  $ = layui.$;
			  //获取头像信息
				wxRequest("/sysUser/getSysNameAndImg",null,function(e){
					$("#nickName").text(e.data.nickName);
				});
				$("#addCategory").hide();
				$("#delCategory").hide();
				
				$("#addCategory").click(function(e){
					layer.open({
					         type: 1
					        ,title: false //不显示标题栏
					        ,closeBtn: true
					        ,area: '600px;'
					        ,shade: 0.1
					        ,id: 'LAY_layuipro1' //设定一个id，防止重复弹出
					        ,btn: ['确定']
					        ,btnAlign: 'c'
					        ,moveType: 1 //拖拽模式，0或者1
					        ,content: '<div style="padding:35px;font-size:15px" class="categoryClass">'
					        +'<div class="layui-col"><label class="layui-form-label">分类名称</label><div class="layui-input-block"><input type="text" id="categoryName" lay-verify="title" autocomplete="off" placeholder="请输入分类名称" class="layui-input"></div>'
							+'</div>'
					        ,success: function(layero){  
					        },
					        yes:function(e,layero){//点了确定后执行
					        	let name = $("#categoryName").val();
					        	if(name!=""&&name!=undefined&&name!=null){
					        		wxRequest("/aCategory/add",{name:name},function(){
					        		layer.close(e);
					        		getShopCustomerManagePageInfo()
								})
					        	}else{
					        		layer.msg("请输入分类名称！");
					        	}
					        }
					})
				});
			});
			
			function logout(){
				wxRequest("/sysUser/logout",null,function(e){
					localStorage.setItem("userkey",null);
					login();
				});
			}
			
			var passStatus;
			function setThisChecked(e){
				passStatus = $(e).val();
			}
			
			function addChecked(e){
				$(e).addClass("checked");
			}
			function setCategoryIds(){
				var tempArr = new Array();
				var arr = $(".categoryCheck");
				for(var i=0;i<arr.length;i++){
					if($(arr[i]).hasClass("checked")){
						tempArr.push($(arr[i]).val())
					}
				}
				return tempArr;
			}
			let toPageFlag = false;
			function toCategorysPage(){
				$("#addCategory").show();
				$("#delCategory").show();
				$("#passBtn").remove();
				toPageFlag = true
				//ajax请求后台数据
       			getShopCustomerManagePageInfo();
			}
			function getCategoryList(artId){
				wxRequest("/aCategory/list",{pageStart:1,pageTotal:50},function(e){
					var categoryList = e.data.data;
					var divContent = "";
					var num = 1;
					for(var i=0;i<categoryList.length;i++){
						if(i%4 ==0){
							divContent+='<label class="category-row">';
							for(var a=1;a<=4;a++){
								num = a + i - 1;
								if(num>=categoryList.length){
									continue
								}
								divContent+='<label class="category-cell"><input type="checkbox" class="categoryCheck" onclick="addChecked(this)" value="'+categoryList[num].categoryId+'" >'+categoryList[num].categoryName+'</input></label>'
							}
							divContent+='</label>'
						}
					}
					
					layer.open({
					         type: 1
					        ,title: false //不显示标题栏
					        ,closeBtn: true
					        ,area: '600px;'
					        ,shade: 0.1
					        ,id: 'LAY_layuipro1' //设定一个id，防止重复弹出
					        ,btn: ['确定']
					        ,btnAlign: 'c'
					        ,moveType: 1 //拖拽模式，0或者1
					        ,content: '<div style="padding:40px;font-size:20px" class="categoryClass">'
					        +divContent
							+'</div>'
					        ,success: function(layero){  
					        },
					        yes:function(e,layero){//点了确定后执行
					        	var data = {};
					        	data.categroyIds = setCategoryIds();
					        	data.artId = artId;
					        	wxRequest("/aCategory/setCategory",{json:JSON.stringify(data)},function(){
					        		layer.close(e);
					        		getShopCustomerManagePageInfo()
					        	})
					        }
					      })
				});
				/**/
			}
		</script>
		<script src="js/jquery-1.10.2.js"></script>
		<script>
	//分页参数设置 这些全局变量关系到分页的功能
	var pageStart = 1;//开始页数
	var pageTotal = 10;//每页显示数据条数
	var currentPageAllAppoint = 1;//当前页数
	var pageCount = 0;//数据总条数
	var ids = [];
	let data;
    $(document).ready(function () {
        //ajax请求后台数据
       getShopCustomerManagePageInfo();
        //点击搜索时 搜索数据
        $("#selectButton").click(function () {
           getShopCustomerManagePageInfo();
            currentPageAllAppoint = 1; //当点击搜索的时候，应该回到第一页
            toPage();//然后进行分页的初始化
        });
        toPage();
    });
    createTable(data);
    //ajax请求后台数据
    function getShopCustomerManagePageInfo() {
    	if(toPageFlag){
    		wxRequest("/aCategory/list",{
					pageStart: pageStart,
                    pageTotal: pageTotal,
		},function(res){
				createTable(res.data.data);
                pageCount = res.data.pageCount;//数据总条数
                pageTotal = res.data.pageTotal;
                pageStart = res.data.pageStart;
                toPage();
			});
    	}else{
    		wxRequest("/aArticle/adminList",{
			pageStart: pageStart,
                    pageTotal: pageTotal,
                    type:1,
		},function(res){
				createTable(res.data.data);
                pageCount = res.data.pageCount;//数据总条数
                pageTotal = res.data.pageTotal;
                pageStart = res.data.pageStart;
                toPage();
    	})}
		 layui.use('element', function() {
                        var element = layui.element;
                        element.init();
                    });
    }
    
    //创建分页表格
    function createTable(data) {
    	  layui.use(['table', 'form', 'element'], function () {
    	        var table = layui.table,element = layui.element,form=layui.form;
    	        if(toPageFlag){
    	        	table.render({
    	            elem: '#LAY_table_user'  //table的id
    	            ,count: pageCount
    	            , cols: [[
    	                {type: 'checkbox', fixed: 'left'}
    	                , {type: 'numbers',fixed: 'left', sort:'true' , width: 50, title: '编号'}
    	                , {field: 'categoryName', width: '200', title: '分类标签', align: 'center'}
                    ]]
    	            , data: data  //数据来源
    	            , id: 'testReload'  //用于表格重载
    	            , limit: pageTotal
    	        });
    	        }else{
    	        	table.render({
    	            elem: '#LAY_table_user'  //table的id
    	            ,count: pageCount
    	            , cols: [[
    	                {type: 'checkbox', fixed: 'left'}
    	                , {type: 'numbers',fixed: 'left', sort:'true' , width: 50, title: '编号'}
//  	                 , {type: 'artId',fixed: 'left', width: 50}
    	                , {field: 'title', width: '200', title: '会议标题', align: 'center'}
    	                , {field: 'categorys', width: '200', title: '分类标签', align: 'center'}
    	                , {field: 'artSeat', width: '200', title: '会议地点', align: 'center'}
                        , {field: 'artUrl', width: '200', title: '会议网址', align: 'center'}
                        , {field: 'status', width: '150',  sort:'true' ,title: '审核状态', align: 'center'}
                        , {field: 'pressTime', width: '150', title: '截稿时间', align: 'center'}
                        , {field: 'startTime', width: '150', title: '开始会议时间', align: 'center'}
                        , {field: 'endTime', width: '150', title: '结束会议时间', align: 'center'}
                        , {field: 'operation', fixed: 'right', title: '操作', width: '150', align: 'center',toolbar:"#barTool"} //这里的toolbar值是模板元素的选择器
                    ]]
    	            , data: data  //数据来源
    	            , id: 'testReload'  //用于表格重载
    	            , limit: pageTotal
    	        });
    	        }
    	        //搜索
/*    	        var active = {
    	            reload: function () {
    	                var demoReload = $('#demoReload');
    	                //执行重载
    	                table.reload('testReload', {
    	                    page: {
    	                        curr: 1 //重新从第 1 页开始}
    	                        , where: {
    	                            key: {
    	                                id: demoReload.val()
    	                            }
    	                        }
    	                    }
    	                });
    	            },
    	        };*/
    	        $('.demoTable .search-btn').on('click', function () {
    	            var type = $(this).data('type');
    	            console.log(type);  //reload
    	            active[type] ? active[type].call(this) : '';
    	        });
    	        //工具条
    	        //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
    	        table.on('tool(categories)', function (obj) { 
    	            var data = obj.data; //获得当前行数据
    	            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
    	            var tr = obj.tr; //获得当前行 tr 的DOM对象
    	            //编辑
    	            if (layEvent === 'pass') {
    	            }
    	            if (layEvent === 'setCategory') {
    	            	getCategoryList(data.artId);
    	            }
    	        });

    	        //复选框---批量删除操作
    	        table.on('checkbox(categories)', function (obj) {
    	            //console.log(obj.type); //如果触发的是全选，则为：all，如果触发的是单选，则为：one
    	           if(toPageFlag){
    	            	if(obj.type == "one"){
	   	                    if(obj.checked){
	   	                    	ids.push(obj.data.categoryId);
	   	                        //console.log(goodsIds);
	   	                    }else{
	   	                        var index = ids.indexOf(obj.data.categoryId)
	   	                        if(index > -1){
	   	                        	ids.splice(index,1);
	   	                        }
	   	                    }
	   	                }else{
	   	                    if(obj.checked){
	   	                    	ids = [];
	   	                        for(var i=0;i<data.length;i++){
	   	                        	ids.push(data[i].categoryId);
	   	                        }
	   	                    }else{
	   	                    	ids = [];
	   	                    }
	   	                }
    	            }else{
    	            	if(obj.type == "one"){
   	                    if(obj.checked){
   	                    	ids.push(obj.data.artId);
   	                        //console.log(goodsIds);
   	                    }else{
   	                        var index = ids.indexOf(obj.data.artId)
   	                        if(index > -1){
   	                        	ids.splice(index,1);
   	                        }
   	                    }
   	                }else{
   	                    if(obj.checked){
   	                    	ids = [];
   	                        for(var i=0;i<data.length;i++){
   	                        	ids.push(data[i].artId);
   	                        }
   	                    }else{
   	                    	ids = [];
   	                    }
   	                }
    	            }
   	        	 	
    	            
    	            //如果选中，点击右上角的删除按钮，执行删除操作
    	            if (obj.checked) { //当前是否选中状态
    	            	$("#delCategory").click(function () {
	                        layer.confirm('真的删除选中的分类么?', {title: '提示'}, function (index) {
	                        	wxRequest("/aCategory/del",{ids:JSON.stringify(ids)},function(){
						        		ids =[];
						        		layer.close(index);
						        		getShopCustomerManagePageInfo()
						        	})
	    	                });
    	                });
    	            	
    	                $("#passBtn").click(function () {
    	    	            if(ids.length>0){
	    	    	            layer.open({
						         type: 1
						        ,title: false //不显示标题栏
						        ,closeBtn: true
						        ,area: '300px;'
						        ,shade: 0.1
						        ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
						        ,btn: ['确定']
						        ,btnAlign: 'c'
						        ,moveType: 1 //拖拽模式，0或者1
						        ,content: '<div style="padding:40px;font-size:20px">'
						        +'<label><input type="radio" name="pass" value="1" onclick="setThisChecked(this)"/>审核通过</label><label><input type="radio" name="pass" onclick="setThisChecked(this)" value="2"/>审核不通过</label>'
								+'</div>'
						        ,success: function(layero){  
						        },
						        yes:function(e,layero){//点了确定后执行
						        	if(passStatus!=undefined&&passStatus!=""){
						        		wxRequest("/aArticle/pass",{artId:JSON.stringify(ids),status:passStatus},function(){
						        		ids =[];
						        		passStatus = undefined;
						        		layer.close(e);
						        		getShopCustomerManagePageInfo()
						        	})
						        	}else{
						        		layer.msg("请选择审核状态！");
						        	}
						        }
						      })
      	                    }else{
      	                    	layer.msg("请选择数据！");
      	                    }
    	                });
    	            }
    	        });
    	    });
      }
    function toPage() {
        layui.use(['table','form', 'laypage','laydate'], function () {
            var table = layui.table,  
            	form = layui.form,
                laydate = layui.laydate,
                laypage = layui.laypage;
                
			form.render();
            //调用分页
            laypage.render({
            	elem: 'paged'
                , count: pageCount //这个是后台返回的数据的总条数
                , limit: pageTotal   //每页显示的数据的条数,layui会根据count，limit进行分页的计算
                , curr: currentPageAllAppoint
                ,layout: ['count', 'prev', 'page', 'next', 'limit','skip'/* , 'refresh' */]
                 , jump: function (obj, first) {
                	//console.log("limit="+obj.limit);
                	//console.log("pageTotal="+pageTotal);
                	pageTotal = obj.limit;
                	//console.log("pageTotal="+pageTotal);
                    currentPageAllAppoint = obj.curr;
               		pageStart = obj.curr;  //当前第几页, pageStart就是多少
                    //document.getElementById('biuuu_city_list').innerHTML = render(obj, obj.curr);
                    if (!first) { //一定要加此判断，否则初始时会无限刷新
                          getShopCustomerManagePageInfo();//一定要把翻页的ajax请求放到这里，不然会请求两次。
                        //location.href = '?page='+obj.curr;
                    } 
                }
            });
        });
    };
	</script>
</body>
</html>